<?php
namespace app\Capital\model;
use think\Model;
use think\Db;

class account extends Model{
    //插入会员账务变动数据
    /*
     * $data单据参数
     * member会员ID
     * no 单据号
     * num 单据金额
     *balance 单据之前会员账户余额（期初）
     */
    public static function add_member_account($data,$account_type=1){
        if($data){
            if($data['memberid'] && $data['no'] && $data ['type']&& $data['num'] && isset($data['balance'])){
                //会员数据
                $Symbol='';
                $member=Db::name('member')->where('id',$data['memberid'])->find();
                    if($member){
                        switch($data['type']){
                            case 1:
                                $Symbol='-';
                                break;
                            case 3;
                                $Symbol='-';
                                break;
                            case 4:
                                if($data['num'] < 0){
                                    $Symbol='-';
                                }else{
                                    $data['type']=15;
                                }
                                break;
                            case 6:
                                $Symbol='-';
                                break;
                            case '11':
                                $Symbol='-';
                                $account_type=2;
                                break;
                            case '12':
                                $account_type=2;
                              //  $data['balance']=$member['temporary_creditlimit'];
                                break;
                            case 13:
                                $account_type=2;
                               // $data['balance']=$member['creditlimit'];
                                break;
                            default:
                                break;
                        }
                        $data['member_name']=$member['company'];
                        $data['num']=$Symbol.$data['num'];
                        $data['account_type']=$account_type;
                        $data['createtime']=time();
                        $result=Db::name('member_account')->insert($data);
                    }else{
                        $result=false;
                    }
            }else{
                $result=false;
            }
        }
        return $result;
    }

    public static function add_shop_account($data,$account_type=1){
        if($data){
            if($data['shopid'] && $data['no'] && $data ['type']&& $data['num'] && isset($data['balance'])){
                //店铺数据
                $Symbol='';
                $member=Db::name('shop')->where('id',$data['shopid'])->find();
                if($member){
                    switch($data['type']){
                        case 1:
                            $Symbol='-';
                            break;
                        case 3;
                            $Symbol='-';
                            break;
                        case 4:
                            if($data['num'] < 0){
                                $Symbol='-';
                            }else{
                                $data['type']=15;
                            }
                            break;
                        case 6:
                            $Symbol='-';
                            break;
                        case '11':
                            $Symbol='-';
                            $account_type=2;
                            break;
                        case '12':
                            $account_type=2;
                            //  $data['balance']=$member['temporary_creditlimit'];
                            break;
                        case 13:
                            $account_type=2;
                            // $data['balance']=$member['creditlimit'];
                            break;
                        default:
                            break;
                    }
                    $data['shop_name']=$member['name'];
                    $data['num']=$Symbol.$data['num'];
                    $data['account_type']=$account_type;
                    $data['createtime']=time();
                    $result=Db::name('shop_account')->insert($data);
                }else{
                    $result=false;
                }
            }else{
                $result=false;
            }
        }
        return $result;
    }

    //订单类型
    public static $orderType=[
        1=>'销售订单',
        2=>'退货单',
        3=>'提现',
        4=>'调整减少',
        5=>'充值单',
        6=>'还款',
        7=>'充值',
        15=>'调整增加',
        11=>'信用额度消费',
        12=>'临时额度增加',
        13=>'固定额度增加',
    ];

}